local skel = fk.CreateSkill {
  name = "efengqi__jueyan",
}

Fk:loadTranslationTable{
  ["efengqi__jueyan"] = "决堰",
  [":efengqi__jueyan"] = "准备阶段，你可以废除装备区/判定区，令〖怀柔〗可以重铸【杀】/重铸装备牌不计次数。均废除后，你使用牌"..
  "无距离限制且手牌上限+3。",

  ["#efengqi__jueyan-invoke"] = "决堰：废除装备区，令“怀柔”可以重铸【杀】；或废除判定区，令“怀柔”重铸装备牌不计次数",

  ["$efengqi__jueyan1"] = "毁堰坝之计，实为阻晋粮道。",
  ["$efengqi__jueyan2"] = "堰坝毁之，可令敌军自退。",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      return player.phase == Player.Start and
        (#player:getAvailableEquipSlots() > 0 or not table.contains(player.sealedSlots, Player.JudgeSlot))
    end
  end,
  on_cost = function (self, event, target, player, data)
    local choices = {}
    if #player:getAvailableEquipSlots() > 0 then
      table.insert(choices, "$Equip")
    end
    if not table.contains(player.sealedSlots, Player.JudgeSlot) then
      table.insert(choices, "JudgeSlot")
    end
    table.insert(choices, "Cancel")
    local choice = player.room:askToChoice(player, { choices = choices, skill_name = skel.name, prompt = "#efengqi__jueyan-invoke"})
    if choice ~= "Cancel" then
      event:setCostData(self, {choice = choice})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event:getCostData(self).choice == "$Equip" then
      room:setPlayerMark(player, "efengqi__jueyan1", 1)
      room:abortPlayerArea(player, player:getAvailableEquipSlots())
    else
      room:setPlayerMark(player, "efengqi__jueyan2", 1)
      room:abortPlayerArea(player, "JudgeSlot")
    end
  end,
})

skel:addEffect(fk.AreaAborted, {
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      return #player:getAvailableEquipSlots() == 0 and table.contains(player.sealedSlots, Player.JudgeSlot)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, MarkEnum.AddMaxCards, 3)
    room:setPlayerMark(player, skel.name, 1)
  end,
})

skel:addEffect("targetmod", {
  bypass_distances =  function(self, player, skill)
    return player:getMark(skel.name) > 0
  end,
})

return skel
